package com.papa91.common;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;
import android.content.res.AssetManager;
import android.os.Environment;
import android.util.Log;

public class BaseAppConfig
{
	public static final boolean IS_DEBUG = true;
	public static String EMU_NAME = "";
	public static final String GUIDE_JSON = "guide.json";
	public static final boolean DEBUG = false;
	static public String APP_PATH = "";
	public static final String PREF_FIRST_RUN = "firstRun";
	public static final String PREF_ENABLE_PHYSICAL_KEY = "enablePhysicalKey";
	public static final String PREF_ENABLE_ONE_CONTROLLER = "enableOneController";
	public static final String PREF_ENABLE_AUDIO = "enableAudio";
	public static final String PREF_RENDER_MODE = "renderMode";
	public static final String PREF_RENDER_QUALITY = "renderQuality";
	public static final String PREF_SHOW_FPS = "showFPS";
	public static final String PREF_SCREENT_ORIENT = "screenOrient";
	public static final String PREF_FRAME_SKIP = "frameSkip";
	public static final String PREF_SCREEN_MODE = "screenMode";
	public static final String PREF_ENABLE_VPAD = "enableVPad";
	public static final String PREF_VPAD_AUTOLAYOUT = "vpadAutoLayout";
	public static final String PREF_ENABLE_VIBRATOR = "enableVibrator";
	public static final String PREF_KEY_EXT1_VAL = "KEY_EXT1_VAL";
	public static final String PREF_KEY_EXT2_VAL = "KEY_EXT2_VAL";
	public static final String PREF_KEY_EXT3_VAL = "KEY_EXT3_VAL";
	public static final String PREF_KEY_EXT4_VAL = "KEY_EXT4_VAL";
	public static final String PREF_TURBO_SPEED = "turboSpeed";
	public static final String PREF_TURBO_ENABLE = "turboEnable";
	public static final String PREF_LAST_NETADDR = "lastNetAddr";
	public static final String AD_JSON_KEY = "adDatas";
	final static public String PREF_ANALOG_PRETTY = "analogPretty";
	final static public String PREF_ANALOG_DZ = "analogDeadzoneNEW";
	final static public String PREF_ANALOG_EZ = "analogExpandzoneNEW";
	final static public String PREF_BUTTON_EZ = "buttonExpandzoneNEW";

	final static public String PREF_TILT_SENSOR = "PREF_TILT_SENSOR";
	final static public String PREF_TILT_DZ = "PREF_TILT_DZ";
	final static public String PREF_TILT_SENSITIVITY = "PREF_TILT_SENSITIVITY";
	// n64 input
	final static public String PREF_VPAD_STYLE = "PREF_VPAD_STYLE";
	final static public int PREF_VPAD_SKIN_1 = 0;
	final static public int PREF_VPAD_SKIN_2 = 1;
	final static public int PREF_VPAD_SKIN_3 = 2;

	final static public String PREF_DEVICE_NAME = "device name:";
	final static public String PREF_DEVICE_DESCRIP = "device descrip:";
	final static public String PREF_PLAYER_KEYMAP = "keymap:";

	final static public String PREF_HIDE_ADS = "hideAds";
	final static public String PREF_VPAD_PLAYER = "vpadPlayer";

	public static final String PREF_AUTO_THREADING = "autoMultiThread";
	public static final String PA_PACKAGE_NAME = "pa_package_name";

	static public int language = 1;
	static public int versionCode;

	static public final int ROMS_MODE_ALL = 0;
	static public final int ROMS_MODE_SUPPORT = 1;
	static public final int ROMS_MODE_FAVOR = 2;
	static public final int ROMS_MODE_BOARD = 3;
	static public final int ROMS_MODE_TYPE = 4;

	static public int curListMode = ROMS_MODE_ALL;
	static public int curBoardType;
	static public int curGameType;

	// static public String STATE_PATH = "/sdcard/papa91/arc/.states/";
	// static public String SNAP_PATH = "/sdcard/papa91/arc/.screenshot/";

	static public String CONFIG_PATH = "config/";
	static public String ROM_PATH = "";
	static public String INFO_PATH = "rominfo/";
	// static public String CHEAT_PATH = "/sdcard/papa91/arc/.cheats/";
	static public String TMP_PATH = "tmp/";
	static public String IPS_PATH = "ips/";
	static public String ROMDATA_PATH = "romdata/";
	static public String PRIVATE_PATH;
	static public String LOG_PATH = "log/"; //added by qyh

	static public final String KEY_ROM_NAME = "romName";
	static public final String KEY_ROM_PATH = "romPath";
	static public final String KEY_UGC_PATH = "ugcPath";
	static public final String KEY_ROM_TITLE = "romTitle";
	static public final String KEY_STATE_PATH = "statePath";

	static public final String KEY_START_MODE = "startMode";
	static public final String KEY_SERVER_IP = "serverIP";
	static public final String KEY_SERVER_PORT = "serverPort";
	static public final String KEY_START_CHEAT = "startCheat";
	static public final String KEY_START_GAMEID = "gameID";
	static public final String KEY_START_USERID = "userID";
	static public final String KEY_START_ROOMID = "roomID";
	static public final String KEY_START_VERSION = "version";
	static public final String KEY_START_PORDER = "porder";
	static public final String KEY_START_JSON = "jsonData";
	public static final String KEY_START_FID = "plugin_area_val";
	public static final String KEY_PLAYER_NAME_1 = "p1Name";
	public static final String KEY_PLAYER_NAME_2 = "p2Name";
	public static final String KEY_SP_LOCK = "sp_lock";
	static public final String KEY_LAST_DIR = "LAST_DIR";
	static public final String KEY_NETTYPE = "tcptype";
	static public final String KEY_UDP_PORT = "udpport";

	static public final String KEY_WEBVIEW_TITLE = "WEBVIEW_TITLE";
	static public final String KEY_WEBVIEW_URL = "WEBVIEW_URL";

	static public final String KEY_NET_STATE = "netState"; //default: ""

	static public final int START_MODE_RESTART = 0;
	static public final int START_MODE_NETSERVER = 1;
	static public final int START_MODE_NETCLIENT = 2;
	static public final int START_MODE_TUTORIAL = 3;
	static public final int START_MODE_LOAD_STATE = 4;
	static public final int START_MODE_RESUME_LAST = 5;
	static public final int START_MODE_WORLD = 6;
	static public final int START_MODE_NETWORK = 7;
	static public final int START_MODE_INVITE = 8;

	static public final int RENDER_MODE_GPU = 1;
	static public final int RENDER_MODE_CPU = 0;

	static public final int MAX_SCREENSHOT_NUM = 32;
	static public final int MAX_STATE_NUMS = 10;
	static public boolean enablePad = true;
	static public boolean bAutoLayoutBtn = true;
	static public boolean enablePhysicalKey = false;
	static public boolean oneController;

	static public boolean enableAudio = true;
	static public boolean enableAutoOri = true;
	static public int renderMode = RENDER_MODE_GPU;
	static public boolean renderQuality = true;

	public static boolean autoSearchRom = false;

	public static final int SCREEN_MODE_FIT = 0;
	public static final int SCREEN_MODE_FULL = 1;
	public static final int SCREEN_MODE_FRAME = 2;
	public static final int SCREEN_MODE_END = 3;

	public static final int SCREEN_MODE_RATIO4TO3 = 3;
	public static final int SCREEN_MODE_RATIO3TO4 = 4;
	public static final int SCREEN_MODE_ORIGIN = 5;

	public static final int STATE_PIC_WIDTH = 160;
	public static final int STATE_PIC_HEIGHT = 90;

	public static int screenMode = SCREEN_MODE_FULL;
	public static int frameSkip = -1;

	public static final int ORIENT_AUTO = 0;
	public static final int ORIENT_LANDSCAPE = 1;
	public static final int ORIENT_PORTRAIT = 2;
	public static final int ORIENT_LANDSCAPE_REV = 3;
	public static final int ORIENT_PORTRAIT_REV = 4;

	public static int screenOrientation = 1;
	public static boolean landscape = false;

	public static boolean enableVibrator = true;
	// public static boolean hideVirtualControl = false;
	public static float controlScale = 1.0f;// 0.9,1.1,1.26
	public static String vkeypadLayout = "bottom_bottom";
	public static int vkeypadTransparency = 30;

	public static boolean IsXperiaPlay;
	final public static int MAX_PLAYER = 4;
	public static int curPlayer = 0;

	// mame input
	public static int waysStick = 8;
	public static int LAND_BUTTONS_KEY = 2;

	public static final String TAG = "PAPAARC";
	public static String lastRomPath = "";

	public static int turboSpeed = 8;

	public static boolean isFirstRun = false;
	public static int cpuCores = 1;
	public static boolean multiThread = false;
	public static final String KEY_SVIP_LEVEL = "sVipLevel";
	public static final String KEY_VIP_LEVEL = "vipLevel";

	public static void copyGuide(Context context)
	{
		File dateDir = Environment.getExternalStorageDirectory();
		String fileDir = dateDir + "/papa91os/";
		AssetManager asset = context.getAssets();
		try
		{
			File file = new File(fileDir, GUIDE_JSON);
			if (!file.exists())
			{
				InputStream istream = asset.open(GUIDE_JSON, AssetManager.ACCESS_BUFFER);

				OutputStream ostream = new FileOutputStream(file);
				byte[] buf = new byte[1024];
				int len;
				while ((len = istream.read(buf)) > 0)
				{
					ostream.write(buf, 0, len);
				}
				ostream.flush();
				ostream.close();
				istream.close();
			}

		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void PrintLog(String tag, String content)
	{
		if (IS_DEBUG)
			Log.i(tag, content);

	}

}
